/*
* $Id: CheckBoxDraw.cpp 100 2010-06-24 09:57:39Z volok-aleksej@yandex.ru $
*
* Copyright 2009 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "CheckBoxDraw.h"
#include "KeyProcess.h"

CCheckBoxDraw::CCheckBoxDraw(const std::tstring& strName)
: CDrawControl(strName){
	if(m_strValue == _T("+"))
		m_bCheck = true;
	else
		m_bCheck = false;
	m_aKeyProcess.push_back(new CSpace(this));
}
CCheckBoxDraw::~CCheckBoxDraw(){}

void CCheckBoxDraw::SetPos(CPoint pos){
	CPoint posRes = pos - m_rect.TopLeft();
	m_rect.MoveToXY(pos);
}

std::tstring CCheckBoxDraw::GetValue(){
	if(m_bCheck)
		return _T("+");
	else
		return _T("-");
}

void CCheckBoxDraw::PaintActive(CDC* dc){
	CBrush brush;
	brush.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
	dc->FillRect(m_rect, &brush);
	brush.DeleteObject();
	PaintNonActive(dc);
}

void CCheckBoxDraw::PaintNonActive(CDC* dc){
	CRect rect(0, 0, 16, 16);
	rect.OffsetRect(m_rect.left + m_rect.Size().cx/2 - 8, m_rect.top + m_rect.Size().cy/2 - 8);
	dc->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONCHECK | (m_bCheck ? DFCS_CHECKED : 0));
}

void CCheckBoxDraw::Resize(){}

void CCheckBoxDraw::ChangeValue(){
	m_bCheck = !m_bCheck;
}

bool CCheckBoxDraw::ProcessMouse(unsigned int nChar, CPoint pos, int param){
	if(nChar == WM_LBUTTONDOWN){
		ChangeValue();
		return true;
	}
	return false;
}